<?php

namespace Shared\Widgets;

abstract class Widget {
    
    abstract public function paste();
    
    /**
     * @var \Doctrine\ORM\EntityManager
     */
    protected $EntityManager;
    protected $config;

    public function __construct(array $config = null) {
        $this->config = $config;
        $this->EntityManager = \Shared\Application::getInstance()->getEntityManager();
    }

    public function sanitize($str, $type = 'string') {
        switch ($type) {
            case 'email':
                $filter = FILTER_SANITIZE_EMAIL;
                break;
            default:
                $filter = FILTER_SANITIZE_STRING;
                break;
        }

        $str = filter_var(trim($str), $filter);

        return $str;
    }

    public function createNotFound($message = 'Page not found!') {
        Application::getInstance()->createNotFound($message);
    }

    public function getRequest() {
        $Request = Application::getInstance()->getRequest();
        return $Request;
    }

    /**
     * 
     * @return \System\Session
     */
    public function getSession() {
        $Session = Application::getInstance()->getSession();

        return $Session;
    }
}
